package com.evan.uyclub.LoadDiaLongs;

import android.app.ActivityManager;
import android.app.Dialog;
import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.evan.uyclub.R;
import com.skydoves.elasticviews.ElasticButton;

import java.util.List;

public class DisActivity extends Dialog {
    private ElasticButton yes, no;
    private Context contexts;

    /**
     * 加载框工具
     *
     * @param context
     */
    public DisActivity(@NonNull Context context) {
        super(context, R.style.dialogs);
        contexts = context;
        setContentView(R.layout.activity_dis);
        yes = findViewById(R.id.yes);
        no = findViewById(R.id.no);

        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TastyToast.makeText(getContext(),"点击了取消~",TastyToast.LENGTH_LONG,TastyToast.SUCCESS);
                dismiss();
            }
        });
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TastyToast.makeText(getContext(),"点击了确定",TastyToast.LENGTH_LONG,TastyToast.SUCCESS);
                // 1. 通过Context获取ActivityManager
                ActivityManager activityManager = (ActivityManager) contexts.getSystemService(Context.ACTIVITY_SERVICE);
                // 2. 通过ActivityManager获取任务栈
                List<ActivityManager.AppTask> appTaskList = activityManager.getAppTasks();
                // 3. 逐个关闭Activity
                for (ActivityManager.AppTask appTask : appTaskList) {
                    appTask.finishAndRemoveTask();
                }
            }


        });
    }

    public void show(boolean type) {
        setCancelable(type); // 返回键是否允许关闭
        setCanceledOnTouchOutside(type); // 点击界面是否允许关闭
        super.show();
    }
}
